#!/usr/bin/perl

require "./mailadmin-lib.pl";
&ReadParse();

my ($vols, $err_msg, $dirpath, $mntroot, $selvol);
my ($fname);

$mntroot = &get_mnt_root();

$dirpath = $in{'dirpath'};
$fname = $in{'childir'};
$selvol = $in{'selvol'};

if ($fname =~ /^\[file\]:(.*)$/)
{
    $fname = $1;
}
else
{
    $err_msg = $text{'err_msg_loadin_no_fname'};
    goto ERROR_OUT;
}

unless ($dirpath)
{
    $err_msg = $text{'err_msg_no_loadin_dir'};
    goto ERROR_OUT;
}

$dirpath = $mntroot . $dirpath;

if (! (-d $dirpath) )
{
    $err_msg = $text{'err_msg_loadin_dir_not_path'};
    goto ERROR_OUT;
}

if (! (-f ($dirpath . "/" . $fname)))
{
    $err_msg = $text{'err_msg_loadin_no_fname'};
    goto ERROR_OUT;
}

$err_msg = &mail_conf_loadin("userdata", $dirpath, $fname, $selvol);
if ($err_msg)
{
    goto ERROR_OUT;
}

&redirect("maildir_edit.cgi");

exit(0);

ERROR_OUT:;
my (@headp, @footp);
@headp = ($text{'error'}, "");
@footp = ("maildir_edit.cgi", $text{'back_maildir'});
&mail_error(\@headp, \@footp, $text{'err_title_load_maildir_conf'}, $err_msg);
